import {userInfo} from "network/homeRequest/HomeRequest";
import * as methods from 'store/methods.const';
const UserInfoMixin = {

  computed:{

    userInfo(){

      let userInfo = this.$store.state.userInfo;

      if (userInfo === null){

        //请求
        if (sessionStorage.getItem('token') === null){

          this.$router.replace('/login');
          return;
        }

        this.loadUserInfo();
      }

      return userInfo;
    },
    userName(){

      return  this.userInfo !== null ? this.userInfo.username:''
    }

  },
  methods:{
    loadUserInfo(){
      userInfo({}).then(data=>{
        this.$store.commit(methods.SAVEUSER,data);
      });
    }
  }

}


export default UserInfoMixin;
